package interfaces.hud;

import org.fenggui.binding.render.ImageFont;
import org.fenggui.util.Color;

import com.jme.system.DisplaySystem;

import interfaces.GUISource;
import interfaces.superWidgets.InterfaceLabel;
import interfaces.superWidgets.UpdateWidget;

public class EventLabel extends InterfaceLabel implements UpdateWidget {
	
	public static final float MAX_SHOW_TIME = 5f;
	
	public static final Color GOOD_COLOR = Color.GREEN;
	public static final Color BAD_COLOR = Color.RED;
	
	private float currentTime;
	private DisplaySystem display;
	
	public EventLabel(ImageFont font) {
		super(font);
		
		setVisible(false);
		display = DisplaySystem.getDisplaySystem();
		setY(display.getHeight() / 9 * 7);
	}
	
	public void showText(String text, boolean goodEvent) {
		setText(text);
		currentTime = MAX_SHOW_TIME;
		setVisible(true);
		
		setX((display.getWidth() / 2) - (getWidth() / 2));
		
		GUISource.setTextColor(this, goodEvent ? GOOD_COLOR : BAD_COLOR);
		
		layout();
	}
	
	@Override
	public void update(float time) {
		if(isVisible()) {
			currentTime -= time;
			if(currentTime <= 0f) setVisible(false);
		}
	}
}